<?php
class Node_data extends Data {
	private $alias = 'admin-yueshihui-com';
	private $tb = 'node';
	private $tb_group = 'node_group';
	private $cols = array('node_id', 'gid', 'name', 'is_menu', 'target', 'controller');
	private $cols_group = array('gid', 'name', 'pid');
	
	/**
	 * 添加节点
	 * @param unknown_type $params
	 */
	public function create($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->insert($this->tb, $params);
	}
	/**
	 * 修改节点信息
	 * @param unknown_type $params
	 * @param unknown_type $cols
	 */
	public function editNode($params, $cols) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->update($this->tb, $cols, $params);
	}
	/**
	 * 删除节点
	 * @param unknown_type $params
	 */
	public function delNode($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->delete($this->tb, $params);
	}
	/**
	 * 获取节点信息
	 * @param unknown_type $params
	 */
	public function nodeInfo($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->one($this->tb, $this->cols, $params);
	}
	/**
	 * 获取节点信息
	 * @param unknown_type $params
	 */
	public function nodeAll($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->select($this->tb, $this->cols, $params);
	}
	/**
	 * 添加分组
	 * @param unknown_type $params
	 */
	public function createGroup($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->insert($this->tb_group, $params);
	}
	/**
	 * 删除分组
	 * @param unknown_type $params
	 */
	public function delGroup($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->delete($this->tb_group, $params);
	}
	/**
	 * 修改分组信息
	 * @param unknown_type $params
	 * @param unknown_type $cols
	 */
	public function editGroup($params, $cols) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->update($this->tb_group, $cols, $params);
	}
	/**
	 * 获取分组信息
	 * @param unknown_type $params
	 */
	public function groupInfo($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->one($this->tb_group, $this->cols_group, $params);
	}
	/**
	 * 分页获取节点信息
	 * @param unknown_type $page
	 * @param unknown_type $size
	 * @param unknown_type $params
	 * @param unknown_type $orderBy
	 */
	public function page($page, $size, $params, $orderBy = '`node_id` DESC') {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->page($this->tb, $this->cols, $params, $orderBy, $page, $size);
	}
	
	/**
	 * 获取节点记录数
	 * @param unknown_type $params
	 */
	public function count($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->count($this->tb, $params);
	}
	/**
	 * 获取分组信息
	 * @param unknown_type $params
	 */
	public function groupsInfo($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->select($this->tb_group, $this->cols_group, $params);
	}
	/**
	 * 获取分组数量
	 * @param unknown_type $params
	 */
	public function countGroup($params) {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->count($this->tb_group, $params);
	}
	/**
	 * 分页获取节点分组信息
	 * @param unknown_type $page
	 * @param unknown_type $size
	 * @param unknown_type $params
	 * @param unknown_type $orderBy
	 */
	public function pageGroup($page, $size, $params, $orderBy = '`node_id` DESC') {
		if(!($db = $this->connect($this->alias))) return false;
		
		return $db->page($this->tb_group, $this->cols_group, $params, $orderBy, $page, $size);
	}
}